# -*- coding: utf-8 -*-
# @Date   : 2021/5/12
# @File   : R66_EG_CASE_EntMajorShareholdersLostLetterRecordCheck.py
# @Author : zhangxuchuo

'''eof
name:申请企业主要股东失信记录校验
code:R66_EG_CASE_EntMajorShareholdersLostLetterRecordCheck
tableName:
columnName:
groups:个人及企业司法校验
dependencies:EG_CASE_DSJ
type:常用指标
datasourceType:在线指标
description:
eof'''

import sys
import re
import datetime
from dateutil.relativedelta import relativedelta
import pandas as pd

reload(sys)
sys.setdefaultencoding('utf-8')

null_type_list = ['', ' ', None, 'null', 'Null', 'NULL', '/', '-', '--']

def getTable(table_Name):
    try:
        data = EG_CASE_DSJ['data'].get(table_Name)
        if data in null_type_list:
            return None
        else:
            if isinstance(data, list) and len(data) == 0:
                return [{}]
            else:
                return data
    except:
        return None

def get_casecodes():
    cases = getTable('SR230')
    if cases is None:
        return 0
    elif cases == [{}]:
        return 0
    else:
        code_list = []
        for i in cases:
            code = i.get('CASECODE')
            if code in null_type_list:
                pass
            else:
                code_list.append(code)
        return code_list

def R66_EG_CASE_EntMajorShareholdersLostLetterRecordCheck():
    code_list = get_casecodes()
    if code_list == 0 or len(code_list) == 0:
        return 0
    else:
        code_unique = list(set(code_list))
        code_num = len(code_unique)
        return code_num

result = R66_EG_CASE_EntMajorShareholdersLostLetterRecordCheck()
# if __name__ == "__main__":
#     file_obj = open(r'C:\Users\john\Desktop\samples\EG_CASE_DSJ.json', 'r')
#     content = file_obj.read()
#     EG_CASE_DSJ = eval(content)['EG_CASE_DSJ']
# # EG_CASE_DSJ = json.loads(content, strict=False)
#     aa = R66_EG_CASE_EntMajorShareholdersLostLetterRecordCheck()
#     print aa